package com.sss.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sss.springcloud.common.Result;
import com.sss.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 降级自定义服务消息返回
 * @author sss
 * @date 2020-03-12 11:51
 **/
@RestController
public class FallbackController {

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/fallback/payment/get/{id}")
    public Result fallback(@PathVariable("id")Integer id){
        if (id==5) {
            throw new IllegalArgumentException("参数不合法异常！！！！\t"+serverPort);
        }else if (id==6){
            throw new RuntimeException("运行时异常！！！\t"+serverPort);
        }
        Payment payment = new Payment(211L, "fallbackTest\t"+serverPort);
        return Result.succes(payment);
    }




    @GetMapping("/fallback/payment/get/two/{id}")
    public Result fallback2(@PathVariable("id")Integer id){
        if (id==5) {
            throw new IllegalArgumentException("参数不合法异常！！！！\t"+serverPort);
        }else if (id==6){
            throw new RuntimeException("运行时异常！！！\t"+serverPort);
        }
        Payment payment = new Payment(211L, "fallbackTest\t"+serverPort);
        return Result.succes(payment);
    }
}
